//
//  DriverEditCell.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2020/8/6.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "DriverEditCell.h"

@interface DriverEditCell ()

@property (nonatomic, strong) UIButton *chooseBtn;
@property (nonatomic, strong) UIImageView *iconImgView;
@property (nonatomic, strong) UILabel *nameLab;
@property (nonatomic, strong) UIImageView *phoneImgView;
@property (nonatomic, strong) UILabel *phoneLab;
@property (nonatomic, strong) UILabel *line;

@end

@implementation DriverEditCell

+ (instancetype)DriverEditCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"DriverEditCell";
    DriverEditCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[DriverEditCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = HexColor(0xffffff);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.chooseBtn = [[UIButton alloc] initWithFrame:CGRectMake(15, (90 - 23) * 0.5, 23, 23)];
        [self.chooseBtn addTarget:self action:@selector(chooseClick) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.chooseBtn];
        
        self.iconImgView = [[UIImageView alloc] initWithFrame:CGRectMake(self.chooseBtn.nim_right + 20, 20, 50, 50)];
        self.iconImgView.backgroundColor = Color_backgroundColor;
        self.iconImgView.layer.masksToBounds = YES;
        self.iconImgView.layer.cornerRadius = 25;
        self.iconImgView.contentMode = UIViewContentModeScaleAspectFill;
        [self.contentView addSubview:self.iconImgView];
        
        self.nameLab = [[UILabel alloc] initWithFrame:CGRectMake(self.iconImgView.nim_right + 10, self.iconImgView.nim_top + 6.5, ScreenW - 15 - (self.iconImgView.nim_right + 10), 17)];
        self.nameLab.font = BoldFontOfSize(16);
        self.nameLab.textColor = HexColor(0x2B2C44);
        [self.contentView addSubview:self.nameLab];
        
        self.phoneImgView = [[UIImageView alloc] initWithFrame:CGRectMake(self.nameLab.nim_left, self.nameLab.nim_bottom + 5 + 1.5, 12, 12)];
        self.phoneImgView.image = [UIImage imageNamed:@"icon_driver_phone"];
        [self.contentView addSubview:self.phoneImgView];
        
        self.phoneLab = [[UILabel alloc] initWithFrame:CGRectMake(self.phoneImgView.nim_right + 6, self.nameLab.nim_bottom + 5, self.nameLab.nim_right - (self.phoneImgView.nim_right + 6), 15)];
        self.phoneLab.textColor = HexColor(0x9C9DB3);
        self.phoneLab.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.phoneLab];
        
        self.line = [[UILabel alloc] initWithFrame:CGRectMake(15, 89, ScreenW - 30, 1)];
        self.line.backgroundColor = Color_backgroundColor;
        [self.contentView addSubview:self.line];
        
        self.height = self.line.nim_bottom;
    }
    return self;
}

-(void)setModel:(DriverMainModel *)model {
    _model = model;
    self.nameLab.text = model.name;
    self.phoneLab.text = model.phone;
    [self.iconImgView sd_setImageWithURL:[NSURL URLWithString:model.headimg]];
    if (model.isSelected) {
        [self.chooseBtn setImage:[UIImage imageNamed:@"icon_choice_sel"] forState:0];
    }else {
        [self.chooseBtn setImage:[UIImage imageNamed:@"icon_backBox_choice"] forState:0];
    }
}

- (void)chooseClick {
    if (self.chooseBlock) {
        self.chooseBlock();
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
